<?php

namespace App\Traits;

trait FilterHelpers
{
    public function sortBy($value = 'id,desc')
    {
        @list($item, $direction) = explode(',', $value);
        $item = $item ?: 'id';
        $direction = (strtolower($direction) === 'desc') ? 'desc' : 'asc';
        $this->orderBy($item, $direction);
    }

    public function search($keyword)
    {
        $this->where('name', 'like', '%' . $keyword . '%');
    }

}